package com.dtx.singleton.cas;

import java.util.concurrent.atomic.AtomicReference;

public class CASSingle {

    private static final AtomicReference<CASSingle> INSTANCE = new
            AtomicReference<CASSingle>();
    private static CASSingle instance;
    private CASSingle() {
    }
    public static final CASSingle getInstance() {
        for (; ; ) {
            CASSingle instance = INSTANCE.get();
            if (null != instance) return instance;
            INSTANCE.compareAndSet(null, new CASSingle());
            return INSTANCE.get();
        }
    }

    public static void main(String[] args) {
        System.out.println(CASSingle.getInstance());
        System.out.println(CASSingle.getInstance());

    }

}
